package com.zcc.blog.controller;


import com.zcc.blog.dto.PasswordDto;
import com.zcc.blog.entity.User;
import com.zcc.blog.service.UserService;
import com.zcc.blog.untils.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zcc
 * @since 2022-09-05
 */
@Api(tags = "用户")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("注册")
    @PostMapping("/add")
    public  Result register(@Validated @RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation("更新头像")
    @PutMapping("/updateAvatar/{id}")
    public  Result updateAvatar(@RequestParam MultipartFile avatar, @PathVariable Long id){
        return userService.updateAvatar(id, avatar);
    }

    @ApiOperation("更新基本信息")
    @PutMapping("/updateInfo")
    public  Result updateInfo(@RequestBody User user){
        return userService.updateUserInfo(user);
    }

    @ApiOperation("更新密码")
    @PutMapping("/updatePassword")
    public  Result updatePassword(@RequestBody PasswordDto passwordDto){
        return userService.updatePassword(passwordDto);
    }
}
